package com.strange.mdl.module.mdl.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
public class ThreadPoolConfig {

    @Bean("ossUploadTaskExecutor")
    public ExecutorService ossUploadTaskExecutor() {
        int corePoolSize = Runtime.getRuntime().availableProcessors() * 2; // 根据 CPU 动态调整
        return new ThreadPoolExecutor(
                corePoolSize,
                corePoolSize + 4,
                60L, TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(200),
                new ThreadPoolExecutor.CallerRunsPolicy());
    }
}